# 编写一个函数来查找字符串数组中的最长公共前缀。
# 如果不存在公共前缀，返回空字符串 ""。

""
def longestCommonPrefix(strs):
    if len(strs) == 0:
        return ""
    min_str = strs[0]
    for i in strs:
        if len(i) < len(min_str):
            min_str = i
    while True:
        if len(min_str) == 0:
            return ""
        for j in strs:
            if not j.startswith(min_str):
                break
        else:
            return min_str
        min_str = min_str[:-1]


print(longestCommonPrefix(["dog","racecar","car"]))
